<template>
    <view>
        <!-- pages/wallet/index.wxml -->
        <view class="headtop" :style="'padding-bottom:' + statusHeight + 'px;'">
            <image src="/static/walletbg.png" mode="aspectFit" class="headtopbg"></image>
            <view class="header" :style="'padding-top:' + statusHeight + 'px;'">
                <navigator open-type="navigateBack" hover-class="none">
                    <image src="/static/back-w.png" mode="aspectFit" class="back"></image>
                </navigator>
                <text class="title" style="color: #fff">{{title}}</text>
            </view>
            <view class="yue">
                <view class="money" @tap="gopage" data-url="/pages/center/setting/xieyi?id=3" style="width:60%">
                    <text>余额</text>
                    <text>{{ yue || 0 }}</text>
                </view>
                <!-- <view class="money" bindtap="gopage" style="margin-left: 0;" data-url="/pages/center/setting/xieyi?id=3">
      <text>剩余时长（小时）</text>
      <text>{{time || 0}}</text>
    </view> -->
                <view class="btn">
                    <text class="tixian" @tap="chongzhi" v-if="pagetype=='jifen'">购买商品</text>
                </view>
				<!-- <view class="btn">
				    <text class="tixian" @tap="chongzhi" v-if="pagetype==2">获得</text>
				</view>
				<view class="btn">
				    <text class="tixian" @tap="gozhuzao" v-if="pagetype==1">获得晶石</text>
				</view> -->
            </view>
        </view>
        <view class="tab">
            <text :class="type == '' ? 'active' : ''" @tap="changetab" data-type="">全部明细</text>
            <text :class="type == '1' ? 'active' : ''" @tap="changetab" data-type="1">支出明细</text>
            <text :class="type == '2' ? 'active' : ''" @tap="changetab" data-type="2">收入明细</text>
        </view>
        <scroll-view style="height: 960rpx" v-if="list && list.length" scroll-y @scrolltolower="onreachbottom">
            <view class="list" v-for="(item, index) in list" :key="index">
                <view>
                    <text>{{ item.title }}</text>
                    <text>{{ item.money }}</text>
                </view>

                <view>
                    <text>{{ item.ctime }}</text>
                    <text></text>
                </view>
            </view>
        </scroll-view>

        <van-empty description="暂无数据" v-if="!list || !list.length" />
    </view>
</template>

<script>
import vanEmpty from '../../components/empty/empty.vue';

// pages/wallet/index.js
const app = getApp();
export default {
    components: {
        vanEmpty
    },
    data() {
        return {
			pagetype:1,
            nextp: 1,
            count: '',
            type: '',
            show: false,
            list: [],
            statusHeight: '',
            yue: '',
            time: '',
			title:'我的钱包'
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        this.statusHeight = app.globalData.statusHeight;
		this.pagetype = options.type;
		this.title = options.type=='jifen'?'我的积分':'我的体验金'
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var that = this;
        this.nextp=1;
        this.init();
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    // onShareAppMessage: function () {
    // }
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */ methods: {
        init() {
            var _this = this;

            _this.$http(
                'center/getmyliushui',
                {
                    p: this.nextp,
                    type: this.type,
                    count: this.count,
					pagetype:this.pagetype
                },
                function (res) {
                    if (_this.nextp == 1) {
                        _this.list = res.data.list;
                        _this.yue = res.data.yue;
                    } else {
                        if (res.data.list) {
                            for (var i = 0; i < res.data.list.length; i++) {
                                _this.list.push(res.data.list[i]);
                            }

                        }
                    }

                    _this.nextp = res.data.nextp
                    _this.count = res.data.total
                    
                }
            );
        },

        changetab(e) {
            var type = e.currentTarget.dataset.type;
            
			this.type = type;
			this.nextp = 1;
            this.init();
        },

        gopage(e) {
            var url = e.currentTarget.dataset.url;
            uni.navigateTo({
                url: url
            });
        },
		gozhuzao(){
			uni.navigateTo({
				url:'/pages/index/index'
			})
		},
        chongzhi() {
           
            uni.navigateTo({
                url: '/pages/shop/index'
            }); // wx.navigateTo({
            //   url: '/pages/wallet/pay',
            // })
        },

        onClose() {
            this.setData({
                show: 0
            });
        },

        gomsg(e) {
            var id = e.currentTarget.dataset.id;
            uni.navigateTo({
                url: '/pages/wallet/mingximsg?id=' + id
            });
        },

        tixian() {
            uni.navigateTo({
                url: '/pages/wallet/tixian'
            });
        },

        /**
         * 页面上拉触底事件的处理函数
         */
        onreachbottom() {
            console.log(123);

            if (this.nextp) {
                this.init();
            }
        }
    }
};
</script>
<style lang="scss">
@import './wallet.scss';
</style>
